package com.example.androidpattern.state;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.example.androidpattern.AppConstant;
import com.example.androidpattern.EMTagHandler;
import com.example.androidpattern.R;
import com.example.androidpattern.state.classes.VendingMachine;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class StateActivity extends AppCompatActivity {

    @BindView(R.id.tv_state_info)
    TextView tvStateInfo;
    @BindView(R.id.btn_state_insert_money)
    Button btnStateInsertMoney;
    @BindView(R.id.btn_state_out_money)
    Button btnStateOutMoney;
    @BindView(R.id.btn_state_choose_goods)
    Button btnStateChooseGoods;
    @BindView(R.id.btn_state_insure_goods)
    Button btnStateInsureGoods;
    private VendingMachine mMachine;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_state);
        ButterKnife.bind(this);

        setTitle("状态模式");
        tvStateInfo.setText(EMTagHandler.fromHtml(AppConstant.STATE_DEFINE));

        mMachine = new VendingMachine(2);
    }

    @OnClick({R.id.btn_state_insert_money,
            R.id.btn_state_out_money,
            R.id.btn_state_choose_goods,
            R.id.btn_state_insure_goods})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_state_insert_money:
                mMachine.insertMoney();
                break;
            case R.id.btn_state_out_money:
                mMachine.outMoney();
                break;
            case R.id.btn_state_choose_goods:
                mMachine.chooseGoods();
                break;
            case R.id.btn_state_insure_goods:
                mMachine.outGoods();
                break;
        }
    }
}